package day19;

import java.util.Scanner;

public class demo5 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int []arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        int q=in.nextInt();
        int max1=0;
        int max2=0;
        int []t=new int[n+1];
        for(int i=0;i<n;i++){
            if(arr[i]>=max1){
                max2=max1;
                max1=arr[i];
            } else if (arr[i]>max2) {
                max2=arr[i];
            }
            t[i+1]=max2;
        }
        for(int i=0;i<q;i++){
            int dex=in.nextInt();
            System.out.println(t[dex]);
        }
    }
}
